package com.oyjd.fw.util;

import org.apache.commons.mail.HtmlEmail;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 简单发送邮件
 * 
 * @author 欧建东
 * @email oyjd@163.com
 * 
 */
public class MailUtil {

	private static Logger log = LoggerFactory.getLogger(MailUtil.class);

	/**
	 * 发送邮件
	 * 
	 * @param host
	 *            发送邮件主机域名
	 * @param fromEmail
	 *            源邮箱地址
	 * @param password
	 *            源邮箱密码
	 * @param toEmail
	 *            目标邮箱
	 * @param subject
	 *            主题
	 * @param content
	 *            内容
	 * @return true:发送成功 false:发送失败
	 */
	public static boolean sendEmail(String host, String fromEmail, String password, String toEmail, String subject, String content) {
		boolean result = false;
		try {
			HtmlEmail hemail = new HtmlEmail();
			hemail.setHostName(host);
			hemail.setAuthentication(fromEmail, password);
			hemail.setCharset("UTF-8");
			hemail.addTo(toEmail);
			hemail.setFrom(fromEmail);
			hemail.setSubject(subject);
			hemail.setHtmlMsg(content);
			hemail.send();
			result = true;
		} catch (Exception e) {
			log.error("发送邮件失败", e);
		}
		return result;
	}
}
